package com.yrd.spring_mvc.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
//逻辑：判断用户是否登录
public class PrivilegeInterceptor implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// 逻辑：判断用户是否登录。本质：判断 session中有没有user
		System.out.println("PrivilegeInterceptor===>preHandle.....");
//		HttpSession session = request.getSession();
//		User user = (User) session.getAttribute("user");
//		if (user == null) {
//			//没有登录
//			System.out.println("request.getContextPath()===>"+request.getContextPath());
//			response.sendRedirect(request.getContextPath()+"/jsp/login.jsp");
//			return false;
//		}
		
		//放行，访问目标资源
		return true;
	}

}
